/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hiruss.imageprocessor.ui;

import com.hiruss.imageprocessor.util.ImageHandler;
import com.hiruss.imageprocessor.util.PointOperations;
import java.awt.image.BufferedImage;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

/**
 *
 * @author Hiru
 */
public class UI extends javax.swing.JFrame {

    private ImageFrame originalImageFrame, editingImageFrame;
    private BufferedImage originalImage, editingImage, tempEditingImage, lastEditingImage;

    /**
     * Creates new form UI
     */
    public UI() {
        initComponents();
        setLocationRelativeTo(null);
    }

    public BufferedImage getEditingImage() {
        return this.editingImage;
    }

    public BufferedImage getOriginalImage() {
        return this.originalImage;
    }

    public ImageFrame getEditingImageFrame() {
        return this.editingImageFrame;
    }

    public void setEditingImage(BufferedImage editingImage) {
        this.tempEditingImage = this.editingImage;
        this.editingImage = editingImage;
        editingImageFrame.updateImage(editingImage);
        undoButton.setEnabled(true);
    }

    public void revert() {
        this.lastEditingImage = this.editingImage;
        this.editingImage = this.tempEditingImage;
        editingImageFrame.updateImage(this.editingImage);
        undoButton.setEnabled(false);
        redoButton.setEnabled(true);
    }

    public void redo() {
        this.tempEditingImage = this.editingImage;
        this.editingImage = this.lastEditingImage;
        editingImageFrame.updateImage(this.editingImage);
        undoButton.setEnabled(true);
        redoButton.setEnabled(false);
    }

    public boolean isRevertible() {
        return !this.editingImage.equals(this.tempEditingImage);
    }

    public void revertToZero() {
        this.editingImage = this.originalImage;
        editingImageFrame.updateImage(this.editingImage);
    }

    public boolean isRevertibleToZero() {
        return !this.editingImage.equals(this.originalImage);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        imagePanel = new javax.swing.JPanel();
        jToolBar1 = new javax.swing.JToolBar();
        openButton = new javax.swing.JButton();
        saveButton = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        undoButton = new javax.swing.JButton();
        redoButton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        rotateLeftButton = new javax.swing.JButton();
        rotateRightButton = new javax.swing.JButton();
        flipHorizontalButton = new javax.swing.JButton();
        flipVerticalButton = new javax.swing.JButton();
        negetiveButton = new javax.swing.JButton();
        grayScaleButton = new javax.swing.JButton();
        normalizeButton = new javax.swing.JButton();
        cropButton = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        resampleButton = new javax.swing.JButton();
        noiseReductionButton = new javax.swing.JButton();
        edgeDetectionButton = new javax.swing.JButton();
        segmentationButton = new javax.swing.JButton();
        representationButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Image Processor");
        setBackground(new java.awt.Color(204, 204, 204));
        setMinimumSize(new java.awt.Dimension(960, 720));
        getContentPane().setLayout(new java.awt.GridBagLayout());

        imagePanel.setLayout(null);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 30;
        gridBagConstraints.ipady = 30;
        gridBagConstraints.weightx = 0.2;
        gridBagConstraints.weighty = 0.2;
        getContentPane().add(imagePanel, gridBagConstraints);

        jToolBar1.setRollover(true);

        openButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/hiruss/imageprocessor/ui/images/fileopen.png"))); // NOI18N
        openButton.setText("Open");
        openButton.setToolTipText("Open image file");
        openButton.setFocusable(false);
        openButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        openButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        openButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(openButton);

        saveButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/hiruss/imageprocessor/ui/images/filesave.png"))); // NOI18N
        saveButton.setText("Save");
        saveButton.setToolTipText("Save edited file");
        saveButton.setEnabled(false);
        saveButton.setFocusable(false);
        saveButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        saveButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        saveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(saveButton);
        jToolBar1.add(jSeparator3);

        undoButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/hiruss/imageprocessor/ui/images/object_rotate_left.png"))); // NOI18N
        undoButton.setText("Undo");
        undoButton.setToolTipText("Undo last operation");
        undoButton.setEnabled(false);
        undoButton.setFocusable(false);
        undoButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        undoButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        undoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                undoButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(undoButton);

        redoButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/hiruss/imageprocessor/ui/images/object_rotate_right.png"))); // NOI18N
        redoButton.setText("Re-do");
        redoButton.setToolTipText("Re-do last operation");
        redoButton.setEnabled(false);
        redoButton.setFocusable(false);
        redoButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        redoButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        redoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                redoButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(redoButton);
        jToolBar1.add(jSeparator1);

        rotateLeftButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/hiruss/imageprocessor/ui/images/Fatcow-Farm-Fresh-Shape-rotate-anticlockwise.png"))); // NOI18N
        rotateLeftButton.setText("Rotate Left");
        rotateLeftButton.setToolTipText("Rotate left");
        rotateLeftButton.setEnabled(false);
        rotateLeftButton.setFocusable(false);
        rotateLeftButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        rotateLeftButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        rotateLeftButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rotateLeftButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(rotateLeftButton);

        rotateRightButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/hiruss/imageprocessor/ui/images/Fatcow-Farm-Fresh-Shape-rotate-clockwise.png"))); // NOI18N
        rotateRightButton.setText("Rotate Right");
        rotateRightButton.setToolTipText("Rotate right");
        rotateRightButton.setEnabled(false);
        rotateRightButton.setFocusable(false);
        rotateRightButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        rotateRightButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        rotateRightButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rotateRightButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(rotateRightButton);

        flipHorizontalButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/hiruss/imageprocessor/ui/images/object_flip_verticaal.png"))); // NOI18N
        flipHorizontalButton.setText("Flip Hrzntl");
        flipHorizontalButton.setToolTipText("Horizontal mirror image");
        flipHorizontalButton.setEnabled(false);
        flipHorizontalButton.setFocusable(false);
        flipHorizontalButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        flipHorizontalButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        flipHorizontalButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                flipHorizontalButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(flipHorizontalButton);

        flipVerticalButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/hiruss/imageprocessor/ui/images/object_flip_horizontal.png"))); // NOI18N
        flipVerticalButton.setText("Flip Vertical");
        flipVerticalButton.setToolTipText("Vertical mirror image");
        flipVerticalButton.setEnabled(false);
        flipVerticalButton.setFocusable(false);
        flipVerticalButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        flipVerticalButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        flipVerticalButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                flipVerticalButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(flipVerticalButton);

        negetiveButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/hiruss/imageprocessor/ui/images/Actions-object-inverse-icon.png"))); // NOI18N
        negetiveButton.setText("Negetive");
        negetiveButton.setToolTipText("Negetive");
        negetiveButton.setEnabled(false);
        negetiveButton.setFocusable(false);
        negetiveButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        negetiveButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        negetiveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                negetiveButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(negetiveButton);

        grayScaleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/hiruss/imageprocessor/ui/images/Zeusbox-Blankon-Grayscale.png"))); // NOI18N
        grayScaleButton.setText("Gray Scale");
        grayScaleButton.setToolTipText("Gray scaling");
        grayScaleButton.setEnabled(false);
        grayScaleButton.setFocusable(false);
        grayScaleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        grayScaleButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        grayScaleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                grayScaleButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(grayScaleButton);

        normalizeButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/hiruss/imageprocessor/ui/images/Zeusbox-Blankon-Grayscale.png"))); // NOI18N
        normalizeButton.setText("Normalize");
        normalizeButton.setToolTipText("Normalizing");
        normalizeButton.setEnabled(false);
        normalizeButton.setFocusable(false);
        normalizeButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        normalizeButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        normalizeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                normalizeButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(normalizeButton);

        cropButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/hiruss/imageprocessor/ui/images/Actions-transform-crop-and-resize-icon.png"))); // NOI18N
        cropButton.setText("Crop");
        cropButton.setToolTipText("Crop image");
        cropButton.setEnabled(false);
        cropButton.setFocusable(false);
        cropButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        cropButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        cropButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cropButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(cropButton);
        jToolBar1.add(jSeparator2);

        resampleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/hiruss/imageprocessor/ui/images/layer-resize-icon.png"))); // NOI18N
        resampleButton.setText("Re-sample");
        resampleButton.setToolTipText("Re-sample image");
        resampleButton.setEnabled(false);
        resampleButton.setFocusable(false);
        resampleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        resampleButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        resampleButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resampleButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(resampleButton);

        noiseReductionButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/hiruss/imageprocessor/ui/images/silhouette_of_maid_with_duster_dusting_as_she_works_0515-1010-0904-2623_SMU.png"))); // NOI18N
        noiseReductionButton.setText("Remove Noise");
        noiseReductionButton.setToolTipText("Apply filters");
        noiseReductionButton.setEnabled(false);
        noiseReductionButton.setFocusable(false);
        noiseReductionButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        noiseReductionButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        noiseReductionButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                noiseReductionButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(noiseReductionButton);

        edgeDetectionButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/hiruss/imageprocessor/ui/images/canny_lena_noisy.png"))); // NOI18N
        edgeDetectionButton.setText("Edge Detection");
        edgeDetectionButton.setToolTipText("Detect Edges");
        edgeDetectionButton.setEnabled(false);
        edgeDetectionButton.setFocusable(false);
        edgeDetectionButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        edgeDetectionButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        edgeDetectionButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                edgeDetectionButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(edgeDetectionButton);

        segmentationButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/hiruss/imageprocessor/ui/images/proj6_1_1_icon.png"))); // NOI18N
        segmentationButton.setText("Segmentation");
        segmentationButton.setToolTipText("Segmentation");
        segmentationButton.setEnabled(false);
        segmentationButton.setFocusable(false);
        segmentationButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        segmentationButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        segmentationButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                segmentationButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(segmentationButton);

        representationButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/hiruss/imageprocessor/ui/images/proj6_1_1_icon_2.png"))); // NOI18N
        representationButton.setText("Representation");
        representationButton.setToolTipText("Representation");
        representationButton.setEnabled(false);
        representationButton.setFocusable(false);
        representationButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        representationButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        representationButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                representationButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(representationButton);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        getContentPane().add(jToolBar1, gridBagConstraints);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void resampleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resampleButtonActionPerformed

        ResamplePanel.getInstance(this).setVisible(true);
    }//GEN-LAST:event_resampleButtonActionPerformed

    private void noiseReductionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_noiseReductionButtonActionPerformed

        FilterPanel.getInstance(this).setVisible(true);
    }//GEN-LAST:event_noiseReductionButtonActionPerformed

    private void openButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openButtonActionPerformed

        BufferedImage bi = ImageHandler.loadImage(this);
        if (bi == null) {
            return;
        }
        if (originalImageFrame != null) {
            imagePanel.remove(originalImageFrame);
            originalImageFrame = null;
        }
        if (editingImageFrame != null) {
            imagePanel.remove(editingImageFrame);
            editingImageFrame = null;
        }
        originalImage = bi;
        originalImageFrame = new ImageFrame(originalImage, "Source Image");
        editingImage = ImageHandler.duplicateImage(originalImage);
        tempEditingImage = ImageHandler.duplicateImage(originalImage);
        lastEditingImage = ImageHandler.duplicateImage(originalImage);
        editingImageFrame = new ImageFrame(editingImage, "Edited Image");
        imagePanel.add(originalImageFrame);
        originalImageFrame.setPosition(12, 12);
        imagePanel.add(editingImageFrame);
        imagePanel.setComponentZOrder(editingImageFrame, 0);
        imagePanel.setComponentZOrder(originalImageFrame, 1);
        editingImageFrame.setPosition(420, 12);

        saveButton.setEnabled(true);
        rotateLeftButton.setEnabled(true);
        rotateRightButton.setEnabled(true);
        flipHorizontalButton.setEnabled(true);
        flipVerticalButton.setEnabled(true);
        normalizeButton.setEnabled(true);
        negetiveButton.setEnabled(true);
        grayScaleButton.setEnabled(true);
        cropButton.setEnabled(true);
        noiseReductionButton.setEnabled(true);
        edgeDetectionButton.setEnabled(true);
        resampleButton.setEnabled(true);
        segmentationButton.setEnabled(true);
        representationButton.setEnabled(true);

        JOptionPane.showMessageDialog(this,
                "You can move and resize images as you like.\n"
                + "Just check on the arrow mark on lower right corner of each image",
                "Do You Know?",
                JOptionPane.INFORMATION_MESSAGE);
    }//GEN-LAST:event_openButtonActionPerformed

    private void rotateLeftButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rotateLeftButtonActionPerformed

        int h = editingImageFrame.getHeight(), w = editingImageFrame.getWidth();
        this.setEditingImage(PointOperations.rotateLeft(this.editingImage));
        editingImageFrame.setFrameSize(h, w);
    }//GEN-LAST:event_rotateLeftButtonActionPerformed

    private void rotateRightButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rotateRightButtonActionPerformed

        int h = editingImageFrame.getHeight(), w = editingImageFrame.getWidth();
        this.setEditingImage(PointOperations.rotateRight(this.editingImage));
        editingImageFrame.setFrameSize(h, w);
    }//GEN-LAST:event_rotateRightButtonActionPerformed

    private void flipHorizontalButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_flipHorizontalButtonActionPerformed

        this.setEditingImage(PointOperations.flipHorizontal(this.editingImage));
    }//GEN-LAST:event_flipHorizontalButtonActionPerformed

    private void flipVerticalButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_flipVerticalButtonActionPerformed

        this.setEditingImage(PointOperations.flipVertical(this.editingImage));
    }//GEN-LAST:event_flipVerticalButtonActionPerformed

    private void negetiveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_negetiveButtonActionPerformed

        this.setEditingImage(PointOperations.negative(this.editingImage));
    }//GEN-LAST:event_negetiveButtonActionPerformed

    private void grayScaleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_grayScaleButtonActionPerformed

        this.setEditingImage(PointOperations.averageGrayscale(this.editingImage));
    }//GEN-LAST:event_grayScaleButtonActionPerformed

    private void normalizeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_normalizeButtonActionPerformed

        this.setEditingImage(PointOperations.normalize(this.editingImage));
    }//GEN-LAST:event_normalizeButtonActionPerformed

    private void cropButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cropButtonActionPerformed

        CropPanel.getInstance(this).setVisible(true);
    }//GEN-LAST:event_cropButtonActionPerformed

    private void edgeDetectionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_edgeDetectionButtonActionPerformed

        EdgeDetectionPanel.getInstance(this).setVisible(true);
    }//GEN-LAST:event_edgeDetectionButtonActionPerformed

    private void segmentationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_segmentationButtonActionPerformed

        SegmentationPanel.getInstance(this).setVisible(true);
    }//GEN-LAST:event_segmentationButtonActionPerformed

    private void representationButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_representationButtonActionPerformed

        RepresentationPanel.getInstance(this).setVisible(true);
    }//GEN-LAST:event_representationButtonActionPerformed

    private void undoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_undoButtonActionPerformed

        revert();
    }//GEN-LAST:event_undoButtonActionPerformed

    private void redoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_redoButtonActionPerformed

        redo();
    }//GEN-LAST:event_redoButtonActionPerformed

    private void saveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveButtonActionPerformed

        ImageHandler.saveImage(editingImage, this);
    }//GEN-LAST:event_saveButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
//        try {
//            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
//                if ("Nimbus".equals(info.getName())) {
//                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
//                    break;
//                }
//            }
//        } catch (ClassNotFoundException ex) {
//            java.util.logging.Logger.getLogger(UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (InstantiationException ex) {
//            java.util.logging.Logger.getLogger(UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (IllegalAccessException ex) {
//            java.util.logging.Logger.getLogger(UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
//            java.util.logging.Logger.getLogger(UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
//        }

        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception ex) {
            System.out.println("Failed to load system look and feel");
        }

        //</editor-fold>

        new UI().setVisible(true);
        /* Create and display the form */
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            @Override
//            public void run() {
//                new UI().setVisible(true);
//            }
//        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cropButton;
    private javax.swing.JButton edgeDetectionButton;
    private javax.swing.JButton flipHorizontalButton;
    private javax.swing.JButton flipVerticalButton;
    private javax.swing.JButton grayScaleButton;
    private javax.swing.JPanel imagePanel;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JButton negetiveButton;
    private javax.swing.JButton noiseReductionButton;
    private javax.swing.JButton normalizeButton;
    private javax.swing.JButton openButton;
    private javax.swing.JButton redoButton;
    private javax.swing.JButton representationButton;
    private javax.swing.JButton resampleButton;
    private javax.swing.JButton rotateLeftButton;
    private javax.swing.JButton rotateRightButton;
    private javax.swing.JButton saveButton;
    private javax.swing.JButton segmentationButton;
    private javax.swing.JButton undoButton;
    // End of variables declaration//GEN-END:variables
}
